package com.android.delivery.adapter.wangdian

import android.widget.TextView
import com.android.delivery.R
import com.android.delivery.entity.NetHomePb
import com.android.delivery.util.DensityUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.wuhenzhizao.sku.utils.ScreenUtils

/**
 * @author: mqwang
 * @create: 2/10/21 12:11 AM
 * @Description:网点端进度条
 */
class NetProgressAdapter : BaseQuickAdapter<NetHomePb, BaseViewHolder>(R.layout.adapter_net_pb) {

    private var mMaxProgress: Int = 100;
    override fun convert(helper: BaseViewHolder, item: NetHomePb) {

        var tvPb = helper.getView<TextView>(R.id.tv_pb)
        var pbWidth = ScreenUtils.getScreenWidth(mContext) - DensityUtil.dp2px(48f)
        if (helper.adapterPosition == 0) {
            val percent = item.target / mMaxProgress.toFloat()
            tvPb.layoutParams.width = (pbWidth * percent).toInt()
        } else {
            val lastItem = data.get(helper.adapterPosition - 1)
            val percent = (item.target - lastItem.target) / mMaxProgress.toFloat()
            tvPb.layoutParams.width =  (pbWidth * percent).toInt() - DensityUtil.dp2px(15f)
        }

        if (helper.adapterPosition == itemCount - 1){
            helper.setGone(R.id.line, false)
        }else{
            helper.setGone(R.id.line, true)
        }
        helper!!.setText(R.id.tv_money, item.award.toString() + "元")
        helper!!.setText(R.id.tv_num, item.target.toString() + "单")
    }

    fun setMaxProgress(target: Int) {
        this.mMaxProgress = target;
    }
}